import { Router } from 'express';
import { UserController } from '../controllers/user.controller';
import { authMiddleware } from '../middlewares/auth.middleware';
import { body, query, validationResult } from 'express-validator';
import { validateMiddleware } from '../middlewares/validate.middleware';
const router = Router();
const userController = new UserController();

// 注册路由
router.post(
  '/register',
  [
    body('account').notEmpty().withMessage('用户名不能为空'),
    body('password').isLength({ min: 6 }).withMessage('密码长度不能小于6位'),
  ],
  validateMiddleware,
  userController.register
);

// 登录路由
router.post(
  '/login',
  [
    body('account').notEmpty().withMessage('用户名不能为空'),
    body('password').notEmpty().withMessage('密码不能为空')
  ],
  validateMiddleware,
  userController.login
);

// 获取用户列表路由
router.get(
  '/list',
  [
    query('pageNo').optional().isInt({ min: 1 }).withMessage('页码必须大于0'),
    query('pageSize').optional().isInt({ min: 1, max: 100 }).withMessage('每页条数必须在1-100之间')
  ],
  authMiddleware,
  validateMiddleware,
  userController.getUserList
);

// 获取用户信息路由
router.get('/info', authMiddleware, userController.getUserInfo);

export default router; 